package com.itqf.springboot_mvc.controller;

import com.itqf.springboot_mvc.pojo.User;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * projectName: springboot_part
 *
 * @author: 赵伟风
 * time: 2021/9/17 14:16
 * description:
 */
@RestController
/**
 * 解决跨域问题的注解
 */
@CrossOrigin("*")
@RequestMapping("user")
public class UserController {


    @GetMapping("list")
    public Object retList(){

        List<User> users = new ArrayList<>();
        User user = new User();
        user.setUsername("二狗子");
        user.setBirthday(new Date());

        users.add(user);
        users.add(user);
        users.add(user);
        users.add(user);
//
//        Map<String,Object> data = new HashMap<>();
//        data.put("name", "二狗子");
//        data.put("age", 20);

        return users;
    }





    /**
     * 接受前端传递的account,password,code
     * @param username
     * @param password
     * @param code
     * @return
     */
    @PostMapping(value = "login")
    public Object login(@RequestParam(value = "account") String username,String password,String code){

        //soutp
        System.out.println("username = " + username + ", password = " + password + ", code = " + code);

        return "username = " + username + ", password = " + password + ", code = " + code;
    }

    /**
     * 注册: url
     * 请求方式: post
     * 参数: username password email age sex
     * 要求: 实体类的属性命名 必须等于前端的参数
     *
     * user参数:默认接 key = value请求参数! 不会接json的值!
     * 怎么去接受json的值!
     *     步骤1:创建一个实体类和json的属性相同
     *     步骤2:形参上添加一个注解 @RequestBody
     * @return
     */
    @PostMapping("register")
    public Object register(@RequestBody User user){
        System.out.println("user = " + user);
        return user;
    }
}
